<template>
	<view>
		<!--upDownLoad组件初始化就会调用获取数据列表-->
		<up-down-load :callback="getList" :top="0">
			<block v-for="(item,index) in list" :key="index">
				<text>{{item}}</text>
			</block>
		</up-down-load>
	</view>
</template>

<script>
	import upDownLoad from '@/components/customer/up-down-load/up-down-load.vue'
	export default {
		components: {
			upDownLoad
		},
		data() {
			return {
				mescroll: null, //保存该分页组件的mescroll对象
				count: 0, //必须将后端返回的数据总数存储下来
				list: [], //数据列表 
			}
		},
		methods: {
			getList(mescroll) {
				this.mescroll = mescroll;
				let params = {},
					that = this;
				params.page = mescroll.num; //页码
				params.size = mescroll.size; //每页数量
				//这里我使用vuex的actions来请求数据
				that.$store.dispatch('getlist', params).then(res => {
					if (res.code == 0) {
						let list = res.data.list; //获取后端返回当前页码的数据
						that.count = res.data.count; //存储后端返回的数据总数
						if (mescroll.num == 1) that.list = []; //如果当前是第一页则置空数据
						that.list = that.list.concat(list); //使用concat方法拼接数据
						mescroll.endBySize(list.length, that.count); //调用endBySize方法,当数据长度为总数的时候结束分页
					} else {
						mescroll.endErr()
					}
				})
			}
		}
	}
</script>